package com.syni.mdd.yhd.common.all.service;

import com.syni.mdd.yhd.common.all.dao.BaseJPADao;
import com.syni.mdd.yhd.common.all.dao.jpa.BmsBusinessCodeDao;
import com.syni.mdd.yhd.common.all.entity.BmsBusinessCode;
import com.syni.mdd.yhd.common.all.entity.BmsBusinessGroupMessage;
import com.syni.mdd.yhd.common.all.service.impl.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
 * @className
 * @description TOO
 * @Author cfx
 * @DATE 2019/4/9 12:04
 * @VERSION 1.0
 **/
@Service
public class BmsBusinessCodeService extends BaseService<BmsBusinessCode, Integer> {

    @Autowired
    BmsBusinessCodeDao bmsBusinessCodeDao;

    @Override
    public BmsBusinessCodeDao getBaseDao() {
        return bmsBusinessCodeDao;
    }

    public void handleRecommendBusiness(Integer recommendBusinessId) {
        Optional<BmsBusinessCode> bmsBusinessCodeOp = bmsBusinessCodeDao.findById(recommendBusinessId);
        if(bmsBusinessCodeOp.isPresent()){
            BmsBusinessCode bmsBusinessCode = bmsBusinessCodeOp.get();
            bmsBusinessCode.setDownloadNum(bmsBusinessCode.getDownloadNum() == null ? 1 : bmsBusinessCode.getDownloadNum() + 1);
            bmsBusinessCodeDao.save(bmsBusinessCode);
        }
    }
}
